package com.itsome.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.itsome.pojo.StaffBuMsgTbl;
import com.itsome.pojo.StaffExcel;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 模拟数据库
 *
 * @author itsome on 2021-01-11 21:03:28
 */
public class DBUtils {
    public static List<StaffExcel> staffList = Lists.newArrayList();

    public static List<StaffBuMsgTbl> staffBuList = Lists.newArrayList();

    public static void insertStaff(List<StaffExcel> list) {
        staffList.addAll(list);
    }

    public static void insertStaffBu(List<StaffBuMsgTbl> list) {
        staffBuList.addAll(list);
    }

    public static Map<String, String> selectUserIdByIdCardNo(List<String> idCardNoList) {
        Map<String, String> resultMap = Maps.newHashMap();
        Map<String, String> dbMap = staffList.stream().collect(Collectors.toMap(StaffExcel::getIdCardNo, StaffExcel::getUserId));
        idCardNoList.forEach(idCardNo -> {
            String userId = dbMap.get(idCardNo);
            if (StringUtils.isNotEmpty(userId)) {
                resultMap.put(idCardNo, userId);
            }
        });
        return resultMap;
    }
}
